/**
 * <p>文件名:		AsyncMethodService.java</p>
 * <p>版权:		CopyrightTag</p>
 * <p>公司:		CompanyTag</p>
 * @author		周华彬(zhouhuabin@sinoiov.com, zhou_hua_bin@163.com)
*/

package com.caits.lbs.framework.services.async;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

import org.slf4j.Logger;

import com.caits.lbs.framework.log.CommonSlf4jLogFactory;

/**
 * <p>AsyncMethodService</p>
 * <p>异步方法执行</p>
 *
 * @author		周华彬(zhouhuabin@sinoiov.com, zhou_hua_bin@163.com)
 * @version		0.0.0
 * <table style="border:1px solid gray;">
 * <tr>
 * <th width="100px">版本号</th><th width="100px">动作</th><th width="100px">修改人</th><th width="100px">修改时间</th>
 * </tr>
 * <!-- 以 Table 方式书写修改历史 -->
 * <tr>
 * <td>0.0.0</td><td>创建类</td><td>admin</td><td>2016年12月26日 下午6:01:41</td>
 * </tr>
 * <tr>
 * <td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td>
 * </tr>
 * </table>
 */
public class AsyncMethodService implements Callable<String>{

	/** 变量:TODO,类型:Logger */
	protected final static Logger LOG = CommonSlf4jLogFactory.getLog();
	

	/* (non-Javadoc)
	 * @see java.util.concurrent.Callable#call()
	 */
	@Override
	public String call() throws Exception {
		LOG.info("开始执行call");
		Thread.sleep(5*1000);
		return "call";
	}
	
	public static void main(String[] args){
		// 1. create future task
		Callable<String> call = new AsyncMethodService();
		FutureTask<String> future = new FutureTask<String>(call);
		// 2. submit future task
		ExecutorService executor = Executors.newFixedThreadPool(1);
		executor.submit(future);
		// 3. do other thing
		// 4. get result, waiting util call method finished
		try {
			LOG.info("Result:" + future.get());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
